package top.xxyu.core;

import lombok.extern.java.Log;

import java.util.HashMap;
import java.util.Map;
@Log
public class ResultData {

    private String code;
    private String msg;
    private Map<String, Object> map = new HashMap<String, Object>();
    private Object result;

    private ResultData(){

    }

    public ResultData(String code, String msg){
         this.code = code;
         this.msg = msg;
    }

    public ResultData(String code, String msg, String result){
        this.code = code;
        this.msg = msg;
        this.result = result;
    }

    public static ResultData success() {
        ResultData msg = new ResultData();
        msg.setCode("200");
        msg.setMsg("成功");
        return msg;
    }

    public static ResultData success(String message) {
        ResultData msg = new ResultData();
        msg.setCode("200");
        msg.setMsg(message);
        return msg;
    }
    public static ResultData success(String message, Object result) {
        ResultData msg = new ResultData();
        msg.setCode("200");
        msg.setMsg(message);
        msg.setResult(result);
        return msg;
    }
    public static ResultData success(Object result) {
        ResultData msg = new ResultData();
        msg.setCode("200");
        msg.setResult(result);
        return msg;
    }
    public static ResultData successData(Object result) {
        ResultData msg = new ResultData();
        msg.setCode("200");
        msg.getMap().put("data",result);
        msg.setResult(msg.getMap());
        return msg;
    }


    public static ResultData error() {
        ResultData msg = new ResultData();
        msg.setCode("201");
        msg.setMsg("失败");
        return msg;
    }
    public static ResultData error(String message) {
        ResultData msg = new ResultData();
        msg.setCode("201");
        msg.setMsg(message);
        return msg;
    }

    public ResultData add(String key, Object value) {
        map.put(key, value);
        return this;
    }


    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getResult() {
        return result;
    }

    public void setResult(Object result) {
        this.result = result;
    }

    public Map<String, Object> getMap() {
        return map;
    }

    public void setMap(Map<String, Object> map) {
        this.map = map;
    }
}
